package icom.acm.action;

import icom.acm.action.Action;
import icom.acm.bean.T_COLLEGE;
import icom.acm.manager.T_CollegeMgr;

public class CollegeAction extends Action{
	private T_COLLEGE college;
	private String token;
	
	public String record() throws Exception {
		String token = (String)session.getAttribute("token");
		if (token==null){
			return "ERROR";
		} else if (!token.equals(this.token)){
			return "ERROR";
		}
		session.removeAttribute("token");
		T_CollegeMgr tcm = new T_CollegeMgr();
		int id = tcm.insert(college);
		if(id == -1){
			return "ERROR";
		}
		college.setC_ID(id);
		return "SUCCESS";
	}
	
	public String delete(){
		String token = (String)session.getAttribute("token");
		if (token==null){
			return "ERROR";
		} else if (!token.equals(this.token)){
			return "ERROR";
		}
		session.removeAttribute("token");
		T_CollegeMgr tcm = new T_CollegeMgr();
		tcm.delete(college.getC_ID());
		return "SUCCESS";
	}
	
	public String update(){
		String token = (String)session.getAttribute("token");
		if (token==null){
			return "ERROR";
		} else if (!token.equals(this.token)){
			return "ERROR";
		}
		session.removeAttribute("token");
		T_CollegeMgr tcm = new T_CollegeMgr();
		int id = tcm.update(college);
		if(id == -1){
			return "ERROR";
		}
		return "SUCCESS";
	}
	
	public T_COLLEGE getCollege() {
		return college;
	}
	public void setCollege(T_COLLEGE college) {
		this.college = college;
	}
	public String getToken() {
		return token;
	}
	public void setToken(String token) {
		this.token = token;
	}
}
